import React from 'react';
import { Result, Button } from 'antd';
import { useNavigate } from 'react-router-dom';
import type { ResultProps } from 'antd';

interface PermissionErrorProps {
  errorType: 'no_permission' | 'department_isolation' | 'role_restriction';
  resourceType?: string;
  targetDepartment?: string;
}

/**
 * 权限错误反馈组件
 * 根据错误类型显示不同的提示信息
 */
export const PermissionError: React.FC<PermissionErrorProps> = ({
  errorType,
  resourceType = '资源',
  targetDepartment
}) => {
  const navigate = useNavigate();
  
  // 根据错误类型生成不同的提示内容
  const getErrorConfig = () => {
    switch (errorType) {
      case 'department_isolation':
        return {
          status: '403' as ResultProps['status'],
          title: '部门隔离',
          subTitle: `您无权访问${targetDepartment ? ` ${targetDepartment} ` : '其他'}部门的${resourceType}`,
          extra: <Button type="primary" onClick={() => navigate(-1)}>返回</Button>
        };
      case 'role_restriction':
        return {
          status: '403' as ResultProps['status'],
          title: '角色限制',
          subTitle: `您的角色无权执行此操作`,
          extra: <Button type="primary" onClick={() => navigate('/')}>返回首页</Button>
        };
      default:
        return {
          status: '403' as ResultProps['status'],
          title: '权限不足',
          subTitle: `您没有足够的权限执行此操作`,
          extra: <Button type="primary" onClick={() => navigate('/')}>返回首页</Button>
        };
    }
  };
  
  const config = getErrorConfig();
  
  return (
    <Result
      status={config.status}
      title={config.title}
      subTitle={config.subTitle}
      extra={config.extra}
    />
  );
};

export default PermissionError; 